package br.com.conhecimento.core.data;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import br.com.conhecimento.core.exception.CoreConhecimentoException;
import br.com.conhecimento.core.model.GestaoCliente;

@Repository
@Transactional
public class GestaoDemandaClienteDaoImpl extends GenericDaoImpl<GestaoCliente, Integer> implements GestaoDemandaClienteDao {

	@Autowired
	@Override
	public void init(SessionFactory sessionFactory) {
		this.setSessionFactory(sessionFactory);
	}
	
	@Override
	public GestaoCliente getCliente(Integer id) throws CoreConhecimentoException {
		Criteria crit = getSession().createCriteria(GestaoCliente.class);
		
		if(id != null) {
			crit.add(Restrictions.eq("id", id));
		}
		
		return (GestaoCliente) crit.uniqueResult();
	}
	
}
